﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cloak.NUnit;
using Cloak.Reflection;
using Moq;
using NUnit.Framework;
using Ruleweaver.Rules;

namespace Ruleweaver.Conditions.Schemas
{
	public class GetConditionFromRepositoryWithOne : Behavior
	{
		private Condition _condition;
		private Mock<IConditionSource> _sourceMock;
		private ConditionRepository _repository;
		private Condition _repositoryCondition;

		protected override void Given()
		{
			var method = Reflect.Func<ICheckable<int>, Check<int>>(Checkable.IsPositive);

			_condition = new Condition(Rule.Check(method), typeof(int));

			_sourceMock = new Mock<IConditionSource>();

			_sourceMock.Setup(source => source.GetConditions()).Returns(new[] { _condition });

			_repository = new ConditionRepository(_sourceMock.Object);
		}

		protected override void When()
		{
			_repositoryCondition = _repository.GetCondition(new ConditionKey(typeof(int)));
		}

		[Then]
		public void ConditionIsOriginal()
		{
			Assert.AreEqual(_condition, _repositoryCondition);
		}
	}
}